package com.milo.thread.code;

import java.util.concurrent.locks.Lock;

/**
 * @author milogenius
 * @date 2020-04-20 17:33
 */
public class MyRunableTwo implements Runnable {

    private static int num = 1;

    private String flag;

    private Lock lock;

    private int threadId;

    MyRunableTwo(String flag, Lock lock,int threadId){
        this.threadId = threadId;
        this.lock=lock;
        this.flag=flag;
    }
    @Override
    public void run() {
        synchronized (lock) {
            while (num <= 45) {
                if (num / 5 % 3 == threadId) {
                    for (int i = 0; i < 5; i++) {
                        System.out.println("线程名称:"+Thread.currentThread().getName()+",num is :"+num++);
                    }
                    lock.notifyAll();
                } else {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }
    }

    public static void main(String[] args) {
        System.out.println(20 / 5 % 3);
    }
}

